#include "clavnum.h"
#include "ui_clavnum.h"

ClavNum::ClavNum(bool admin, QWidget *p) :
    QWidget(p),
    ui(new Ui::ClavNum)
{
    ui->setupUi(this);
    ui->Dot->setVisible(admin);
    parent = p;
    ui->Ponct->setVisible(admin);

    ui->Interog->setVisible(false);
    ui->Exclam->setVisible(false);
}

ClavNum::~ClavNum()
{
    delete ui;
}

void ClavNum::on_Digit_0_pressed(){

    if(!ui->Ponct->isChecked()){
        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_0,Qt::NoModifier,"0",true);
        QCoreApplication::sendEvent(parent->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Ampersand,Qt::NoModifier,"&",true);
        QCoreApplication::sendEvent(parent->focusWidget(),&event);
    }
}

void ClavNum::on_Digit_1_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_1,Qt::NoModifier,"1",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_BracketLeft,Qt::NoModifier,"[",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_2_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_2,Qt::NoModifier,"2",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Minus,Qt::NoModifier,"-",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_3_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_3,Qt::NoModifier,"3",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_BracketRight,Qt::NoModifier,"]",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_4_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_4,Qt::NoModifier,"4",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Underscore,Qt::NoModifier,"_",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_5_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_5,Qt::NoModifier,"5",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_AsciiTilde,Qt::NoModifier,"~",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_6_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_6,Qt::NoModifier,"6",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_AsciiCircum,Qt::NoModifier,"^",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_7_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_7,Qt::NoModifier,"7",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Percent,Qt::NoModifier,"%",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_8_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_8,Qt::NoModifier,"8",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,924,Qt::NoModifier,"µ",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Digit_9_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_9,Qt::NoModifier,"9",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_twosuperior,Qt::NoModifier,"²",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Dot_pressed(){

    if(!ui->Ponct->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Comma,Qt::NoModifier,",",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}else{

    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Period,Qt::NoModifier,".",true);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}
}

void ClavNum::on_Retour_pressed(){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Backspace,Qt::NoModifier);
    QCoreApplication::sendEvent(parent->focusWidget(),&event);
}

void ClavNum::on_Ponct_clicked(bool checked)
{
    if(checked){
        ui->Interog->setVisible(true);
        ui->Exclam->setVisible(true);

        ui->Digit_1->setText(tr("["));
        ui->Digit_2->setText(tr("-"));
        ui->Digit_3->setText(tr("]"));
        ui->Digit_4->setText(tr("_"));
        ui->Digit_5->setText(tr("~"));
        ui->Digit_6->setText(tr("^"));
        ui->Digit_7->setText(tr("%"));
        ui->Digit_8->setText(tr("µ"));
        ui->Digit_9->setText(tr("²"));
        ui->Digit_0->setText(tr("&"));
        ui->Dot->setText(tr("."));

    }else{

        ui->Interog->setVisible(false);
        ui->Exclam->setVisible(false);

        ui->Digit_0->setText("0");
        ui->Digit_1->setText("1");
        ui->Digit_2->setText("2");
        ui->Digit_3->setText("3");
        ui->Digit_4->setText("4");
        ui->Digit_5->setText("5");
        ui->Digit_6->setText("6");
        ui->Digit_7->setText("7");
        ui->Digit_8->setText("8");
        ui->Digit_9->setText("9");
        ui->Dot->setText(",");
    }

}



void ClavNum::on_Interog_clicked()
{
    if(ui->Ponct->isChecked()){
        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Question,Qt::NoModifier,"?",true);
        QCoreApplication::sendEvent(parent->focusWidget(),&event);
    }
}

void ClavNum::on_Exclam_clicked()
{
    if(ui->Ponct->isChecked()){
        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Exclam,Qt::NoModifier,"!",true);
        QCoreApplication::sendEvent(parent->focusWidget(),&event);
    }
}
